package com.izocen.rules.common;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class EasyStringUtils {
	
	public static final String PATTERN_OPERATOR = "\\S+ \\S+ \\S+"; //pattern
	
	public static String processTemplate(String template, Map<String, String> params){
	    StringBuffer sb = new StringBuffer();
	    Matcher m = Pattern.compile("\\$\\{\\w+\\}").matcher(template);
	    while (m.find()) {
	        String param = m.group();
	        String value = params.get(param.substring(2, param.length() - 1));
	        m.appendReplacement(sb, value==null ? "''" : "'"+value+"'");
	    }
	    m.appendTail(sb);
	    return sb.toString();
	}
	
	
    public static boolean matchOperator(String operator) {
		return Pattern.matches(PATTERN_OPERATOR, operator);
	}
}
